/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rate;

import javax.jws.WebService;

/**
 *
 * @author administrator
 */
@WebService()
public class CurrencyRate {

    private final double EURO_DOLLAR = 1.31279;
    private final double DOLLAR_EURO = 0.761738;
    private final double EURO_YUAN = 8.30617;
    private final double YUAN_EURO = 0.120392;
    private final double DOLLAR_YUAN = 6.32723;
    private final double YUAN_DOLLAR = 0.158047;

    public double getRate(String fromCurrency, String toCurrency) {
        double rate = -1;

        if (fromCurrency.equals("euro")) {
            if (toCurrency.equals("dollar")) {
                rate = EURO_DOLLAR;
            } else if (toCurrency.equals("yuan")) {
                rate = EURO_YUAN;
            } else if (toCurrency.endsWith("euro")) {
                rate = 1;
            }
        } else if (fromCurrency.equals("dollar")) {
            if (toCurrency.equals("euro")) {
                rate = DOLLAR_EURO;
            } else if (toCurrency.equals("yuan")) {
                rate = DOLLAR_YUAN;
            } else if (toCurrency.endsWith("dollar")) {
                rate = 1;
            }
        } else if (fromCurrency.equals("yuan")) {
            if (toCurrency.equals("dollar")) {
                rate = YUAN_DOLLAR;
            } else if (toCurrency.equals("euro")) {
                rate = YUAN_EURO;
            } else if (toCurrency.endsWith("yuan")) {
                rate = 1;
            }
        }
        return rate;
    }
}
